package com.njh.charges.controller.apis;

import com.alipay.api.AlipayApiException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hos.entity.his.OrderBackfee;
import com.hos.entity.his.OrderBackfeeItem;
import com.hos.vo.Result;
import com.njh.charges.service.BackFeeService;
import com.njh.charges.vo.AllOrderBackFeeVo;
import com.njh.charges.vo.OrderBackfeeVo;
import com.njh.charges.vo.OrderChargeDtoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author ：njh
 * @date ：Created in 2023/12/15 16:43
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/charges/api/backfee")
@Api(tags = "退费列表相关接口")
public class ApiBackFeeController {

    @Resource
    private BackFeeService backFeeService;

    @PostMapping("queryAllOrderBackfeeForPage")
    @ApiOperation("分页查询所有退费订单")
    public Result queryAllOrderBackfeeForPage(@RequestBody AllOrderBackFeeVo allOrderBackFeeVo) {

        Page<OrderBackfee> orderBackfeePage = backFeeService.queryAllOrderBackfeeForPage(allOrderBackFeeVo);
        Result<Page<OrderBackfee>> result = new Result<Page<OrderBackfee>>(200, "查询成功", orderBackfeePage);

        return result;
    }

    @GetMapping("queryOrderBackfeeItemByBackId/{backId}")
    @ApiOperation("根据订单ID查询订单详情")
    public Result queryOrderBackfeeItemByBackId(@PathVariable String backId) {

        List<OrderBackfeeItem> orderBackfeeItems = backFeeService.queryOrderBackfeeItemByBackId(backId);
        Result<List<OrderBackfeeItem>> result = new Result<List<OrderBackfeeItem>>(200, "查询成功", orderBackfeeItems);

        return result;
    }

    @GetMapping("getChargedCareHistoryByRegId/{regId}")
    @ApiOperation("根据挂号ID查询已支付的处方信息及详情")
    public Result getChargedCareHistoryByRegId(@PathVariable String regId) {

        Map chargedCareHistoryByRegId = backFeeService.getChargedCareHistoryByRegId(regId);
        Result<Map> result = new Result<>(200, "查询成功", chargedCareHistoryByRegId);

        return result;
    }

    @PostMapping("createOrderBackfeeWithCash")
    @ApiOperation("创建现金退费订单")
    public Result createOrderBackfeeWithCash(@RequestBody OrderBackfeeVo orderBackfeeVo) {

        Boolean orderBackfeeWithCash = backFeeService.createOrderBackfeeWithCash(orderBackfeeVo);
        Result<Boolean> result = new Result<>(200, "现金退款成功", orderBackfeeWithCash);

        return result;
    }

    @PostMapping("createOrderBackfeeWithZfb")
    @ApiOperation("创建支付宝退费订单")
    public Result createOrderBackfeeWithZfb(@RequestBody OrderBackfeeVo orderBackfeeVo) throws AlipayApiException {

        String orderBackfeeWithZfb = backFeeService.createOrderBackfeeWithZfb(orderBackfeeVo);
        Result<String> result = new Result<>(200, "支付宝退款成功", orderBackfeeWithZfb);

        return result;
    }


}